package cn.concurrence.juc;

import java.util.concurrent.Semaphore;
import java.util.concurrent.TimeUnit;

/**
 * @author summit
 * @since 2022/4/24 14:45
 */
public class SemaphoreTest {

	public static void main(String[] args) {
		Semaphore sp = new Semaphore(3);

		for (int i = 0; i < 5; i++) {
			new Thread(() -> {
				try {
					sp.acquire();
					System.out.println("抢到车位===========");
					TimeUnit.SECONDS.sleep(2);
				} catch (InterruptedException e) {
					e.printStackTrace();
				} finally {
					System.out.println("开车回家=====");
					sp.release();
				}
			}).start();
		}
	}
}
